import React, { PureComponent } from 'react';

const scaleNames = {
  c: 'Celsius',
  f: 'Fahrenheit',
};

// 摄氏度的输入框组件
export default class TemperatureInput extends PureComponent {
  handleChange = (e) => {
    // this.setState({ temperature: e.target.value });
    this.props.onTemperatureChange(e.target.value);
  };

  render() {
    // const { temperature } = this.state;
    const { scale, temperature } = this.props;
    return (
      <fieldset>
        <legend>在{scaleNames[scale]}:中输入温度数值</legend>
        <input value={temperature} onChange={this.handleChange} />
      </fieldset>
    );
  }
}
